package algorithm.lanqiao.t19727;

import java.io.*;
import java.util.Arrays;

public class Main {
    static class io {
        // 读
        static InputStreamReader ins = new InputStreamReader(System.in);
        static StreamTokenizer in = new StreamTokenizer(ins);
        static BufferedReader br = new BufferedReader(ins);

        // 写
        public static PrintWriter out = new PrintWriter(System.out);


        public static int readInt() {
            try {
                in.nextToken();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }

        public static String readLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public static double readDouble() {
            try {
                in.nextToken();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return in.nval;
        }
    }
    static int[][] g;
    static int n;
    public static void main(String[] args) {
        int t = io.readInt();
        while (t-- > 0) {
            n = io.readInt();
            g = new int[n+1][n+1];
            for (int i = 1; i <= n; i++) {
                for(int j = 1; j <= n; j++) {
                    g[i][j] = io.readInt();
                }
            }
            // 第一种图形 选择0 个90度
            if(dfs(1,0)) {
                io.out.println("Yes");
            }else {
                io.out.println("No");
            }
        }
    }

    /**
     *
     * @param t 第几个图像
     * @param x 旋转多少个90度
     * @return 是否成功
     */
    private static boolean dfs(int t, int x) {
        if(t == 5) {
            return true;
        }
        if(x == 4) {
            return false;
        }
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                if(g[i][j] == 1) {
                    if(check(t,x)) {
                        dfs(t+1,0);
                    }
                }
            }
        }
        return false;

    }

    private static boolean check(int t, int x) {
        return false;
    }
}
